﻿/// <reference path="AttachedHandler.js" />

function HashChangeHandler(obj, handler, binding, argList)
{
	this.AttachedHandler(obj, "hashchange", handler, binding, argList);
}
HashChangeHandler.Inherit(AttachedHandler);

if (____a)
{
	HashChangeHandler.prototype = new AttachedHandler();
	HashChangeHandler.prototype.AttachedHandler = new AttachedHandler();

}

HashChangeHandler._last = null;
HashChangeHandler._intervalId = null;
HashChangeHandler._handlers = new Array();

HashChangeHandler._interval_Callback = function _interval_Callback()
{
	if (HashChangeHandler._last != location.hash)
	{
		HashChangeHandler._last = location.hash;
		for (var i = 0; i < HashChangeHandler._handlers.length; ++i)
		{
			var ae = HashChangeHandler._handlers[i];

			ae._fnToCall();
		}
	}
}

HashChangeHandler._EnsureInterval = function _EnsureInterval()
{
	if (HashChangeHandler._intervalId == null && HashChangeHandler._handlers.length > 0)
	{
		HashChangeHandler._last = location.hash;
		HashChangeHandler._intervalId = setInterval(HashChangeHandler._interval_Callback, 50);
	}
	else if (HashChangeHandler._intervalId != null && HashChangeHandler._handlers.length == 0)
	{
		clearInterval(HashChangeHandler._intervalId);
		HashChangeHandler._intervalId = null;
	}
}

HashChangeHandler.prototype._DoAdd = function _DoAdd()
{
	HashChangeHandler._handlers.push(this);
	HashChangeHandler._EnsureInterval();
}

HashChangeHandler.prototype._Remove = function _Remove()
{
	HashChangeHandler._handlers.Remove(this);
	HashChangeHandler._EnsureInterval();
}

